package com.breeze.blockchain.socket.handler;

import cn.hutool.core.util.StrUtil;
import java.util.Arrays;
import lombok.Getter;

/**
 * webSocket命令
 *
 * @author breeze
 */
@Getter
public enum WebSocketCmd {
  PING(0, "ping"),
  ONLINE(1, "online"),
  ;

  private final int code;
  private final String cmd;

  WebSocketCmd(int code, String cmd) {
    this.code = code;
    this.cmd = cmd;
  }

  public static WebSocketCmd fromCode(String cmd) {
    return Arrays.stream(values())
        .filter(s -> StrUtil.equals(s.getCmd(), cmd))
        .findFirst()
        .orElse(null);
  }
}
